/**
* @Title: warning_ctrl.js
* @Description: TODO
* Copyright: Copyright (c) 2014 
 * Company:中国平安
*
* @Project HIMS-FWA
* @date 2014年10月27日 下午4:43:38
* @version V1.0
*/
;
(function(){
	'use strict';
	
	var app = angular.module('fwa.mainApp');
	app.controller('AuditCanceCtrl', ['$scope','CaseCommonService','CaseAuditDispathAddResultService','CaseAuditProjectAddService',
	                                  '$state','BaseURL','Modal','$stateParams','AuditCanceService',
	                                function($scope,CaseCommonService,CaseAuditDispathAddResultService,CaseAuditProjectAddService,
                                            $state,baseUrl,Modal,$stateParams,AuditCanceService){
		 $scope.requestParam = {
	                page:"1",
	                pageSize:"20"
	            };
		 
        $scope.UrlParams = $stateParams;

		$scope.problemtab=[ {label:'事件处理',id:0,url:'views/hcpms/audit/caseAduitDispathDealProblem.html'},
		                    {label:'调查结果',id:1,url:'views/hcpms/audit/caseAduitProjectDetails.html'}];
//		views/hcpms/audit/problemSearch/caseCheckSurveyResult.html
        $scope.selectedTable = $scope.problemtab[0];
        $scope.tabIndex = 0;
        $scope.tabClicks = function(tab) {
            $scope.selectedTabs = tab;
            $scope.tabIndex = tab.id;

            if( $scope.tabIndex == 0){
                initdealPorblemData();
            }
            if( $scope.tabIndex == 1){ 
                initProblem();
            }
        }
        
        var problemNo = $stateParams.problemNo;
        
        var problemStatus = $stateParams.problemStatus;
		
		//初始化请求参数
        var params = function (){
            var params = {
                problemNo:problemNo,
                page:$scope.requestParam.page,
                pageSize:$scope.requestParam.pageSize
            }
            return params;
        }
        /**
         * 初始化医疗机构数据
         */
        function initdealPorblemData(){
            var parameter=params();
            CaseAuditDispathAddResultService.loadDealProblemData(parameter).success(function(response){
                 $scope.treatmentOpinion = response.result.treatmentOpinion;
                 $scope.auditOpinion = response.result.auditOpinion;
            });
        }
        /**
         * 调查结果
         */
        function  initProblem() {
            var parameter = params();
            CaseAuditProjectAddService.queryOpinionData(parameter).success(function(response){
                $scope.treatmentOpinions = response.result.treatmentOpinion;
                $scope.auditOpinions = response.result.auditOpinion;
                $scope.audit = response.result.audit;
                console.log(response.result);
            });
        }


        /**
         * 初始化医疗机构数据和医护人员信息和参保人信息
         */
        $scope.medicalCode = '';
        function initMedicalData() {
            var parameter = params();
            CaseCommonService.loadMedicalInfoList(parameter).success(function(response){
                $scope.medicalData2=response.medicalBean.medicalList;
                if($scope.medicalData2.length>0)
                {
                    if($scope.medicalData2[0].medicalCode)
                    {
                        $scope.medicalCode=$scope.medicalData2[0].medicalCode;
                    }
                }
                $scope.staffData2 = response.staffBean.staffList;
                $scope.insuranceData2 = response.insuranceBean.insuranceList;
                
                CaseCommonService.initStaffAndInsuranceTempList($scope);

            });
        }

        /**
         * 初始化事件数据对象
         */
        $scope.object = {};
        function initProblemData() {
            var parameter = params();
            CaseCommonService.loadProblemData(parameter).success(function(response){
            	console.log(response.problemObj);
                $scope.object= response.problemObj;
            });
        }
		
        /**
         * 点击医疗机构量事件
         * 
         */
        $scope.$on('fwaInvolve.medicalCountClick',function(){
     	   CaseCommonService.viewMedicalDetail($scope);
        });
        
        /**
         * 点击医务人员总数量事件
         */
        $scope.$on('fwaInvolve.staffCountClick',function(){
        	CaseCommonService.viewStaffList($scope);
        });
        
        /**
         * 点击参保人总数量事件
         */
        $scope.$on('fwaInvolve.insuranceCountClick',function(){
        	CaseCommonService.viewInsurList($scope);
        });
        
        /**
         * 返回
         */
        $scope.goBack = function () {
            $state.go("problemResearch.problemResearchList");
        };

        $scope.loading = false;
        
        
        /**
         * 撤回
         */
        $scope.goCance = function () {
        	Modal.confirm("您确定撤回事件号为“"+problemNo+"”的事件吗？",function(){
        		$scope.loading = true;
        		var param = {problemCode:problemNo,problemStatus:problemStatus};
            	AuditCanceService.auditProblemCance(param).success(function(res){
            		Modal.alert(res.msg);
            		if (res.starts == "0") {
            			$scope.goBack();
            		}
            		$scope.loading = false;
            	}).error(function(e){
            		$scope.loading = false;
            		Modal.alert(e.msg);
            	});
        	});
        };
        /**
         * 查看事件信息对象中案件来源对话框
         */
        $scope.$on('fwaAuditLeft.showModal',function(){
     	   $scope.problemObj = $scope.object;
     	   CaseCommonService.showProblemFromSourceDialog($scope);
        });
        
        initProblemData();
        initMedicalData();
        $scope.tabClicks($scope.problemtab[1]);

        
        
        
   }]);
})();
